package com.luo.service;

import com.luo.dao.impl.UserDaoImpl;
import com.luo.model.GetUserInfoVO;
import com.luo.model.User;

import java.util.List;

/**
 * 功能：用户service
 * 作者：Luo。
 * 日期：2024/1/25 11:39
 */
public class UserService {

    UserDaoImpl userDao = new UserDaoImpl();

    public User queryUserByUserNameAndPassWord(User user) {
        User userByUserNameAndPassWord = userDao.queryUserByUserNameAndPassWord(user);
        return userByUserNameAndPassWord;
    }

    public User queryUserById(String id) {
        User user = userDao.queryUserById(id);
        return user;
    }

    public int adminChangePassword(User user) {
        int i = userDao.adminChangePassword(user);
        return i;
    }

    public int updateAdmin(User user) {
        int i = userDao.updateAdmin(user);
        return i;
    }

    public int updateAdminPicture(User user) {
        int i = userDao.updateAdminPicture(user);
        return i;
    }

    public User queryUserByUserName(String username) {
        User user = userDao.queryUserByUserName(username);
        return user;
    }

    public List<GetUserInfoVO> getUserInfo() {
        List<GetUserInfoVO> userList = userDao.getUserInfo();
        for (GetUserInfoVO user : userList) {
            String birthday = user.getBirthday();
            if (birthday != null) {
                user.setBirthday(birthday.substring(0, birthday.indexOf(" ")));
            }
        }
        return userList;
    }

    public int deleteUserByIds(List list) {
        int rows = userDao.deleteUserByIds(list);
        return rows;
    }

    public int updateUserInfo(GetUserInfoVO user) {
        int i = userDao.updateUserInfo(user);
        return i;
    }

    public User queryUserByPhonne(String phone) {
        User user = userDao.queryUserByPhonne(phone);
        return user;
    }
}
